package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * com.sky.mapper
 * OrderMapper
 *
 * @since 2024/11/4
 */
@Mapper
public interface OrderMapper {
   void insert(Orders orders);

   /**
    * 历史订单查询
    * @return
    */
   Page<Orders> pageQuery(OrdersPageQueryDTO orderPageQueryDTO);

   /**
    * 根据订单号查询订单
    * @param orderNumber
    */
   @Select("select * from orders where number = #{orderNumber}")
   Orders getByNumber(String orderNumber);

   /**
    * 修改订单信息
    * @param orders
    */
   void update(Orders orders);

   /**
    * 根据订单id查询订单详情
    * @param id
    * @return
    */
   @Select("select * from orders where id = #{id}")
   Orders getById(Long id);
   /**
    * 根据状态统计订单数量
    * @param status
    */
   @Select("select count(id) from orders where status = #{status}")
   Integer countStatus(Integer status);

   /**
    * 定时处理超时订单
    *
    * @param pendingPayment
    * @param plusMinutes
    * @return
    */
   @Select("select * from orders where status = #{pendingPayment} and order_time < #{plusMinutes} ")
   List<Orders> getByStatusAndOrderTime(Integer pendingPayment, LocalDateTime plusMinutes);

   /**
    * 查询日期区间的营业额
    * @param map
    * @return
    */
   Double selectTurnoverByDates(Map<String,Object> map);

   /**
    * 查询订单个数
    * @param map
    * @return
    */
   Integer getOrderCount(Map map);

   /**
    * 获取商品销量
    * @param beginTime
    * @param endTime
    * @return
    */
   List<GoodsSalesDTO> getGoodsSales(LocalDateTime beginTime, LocalDateTime endTime);

}
